package com.y.core.toolbox.ajax;

/**
 * rest返回的数据格式
 * @author carl
 *
 */
class Status {
	/**
	 * 成功status_code为0,失败为1,错误为999
	 */
	private String status_code = "0", status_reason;

	public String getStatus_code() {
		return status_code;
	}

	public void setStatus_code(String status_code) {
		this.status_code = status_code;
	}

	public String getStatus_reason() {
		return status_reason;
	}

	public void setStatus_reason(String status_reason) {
		this.status_reason = status_reason;
	}
}
/**
 * rest格式返回格式
 * @author carl
 *
 */
public class RestResult {
	private static final String SUCCESS="0",FAIL="1",ERROR="999",WARN="2";
	private Object result;
	private Status status=new Status();

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}
	public RestResult setStatus_reason(String status_reason) {
		this.status.setStatus_reason(status_reason);
		return this;
	}

	public RestResult addSuccess(String status_reason) {
		this.status.setStatus_code(SUCCESS);
		return setStatus_reason(status_reason);
	}

	public RestResult addError(String status_reason) {
		setStatus_reason(status_reason);
		this.status.setStatus_code(ERROR);
		return this;
	}

	public RestResult addFail(String status_reason) {
		setStatus_reason(status_reason);
		this.status.setStatus_code(FAIL);
		return this;
	}

	public RestResult addWarn(String status_reason) {
		setStatus_reason(status_reason);
		this.status.setStatus_code(WARN);
		return this;
	}
	public RestResult setCode(String code) {
		this.status.setStatus_code(code);
		return this;
	}

	public RestResult success(Object data) {
		setResult(data);
		return this;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}
}
